import request from '../../utils/request'
import {
  IAssignRoleResponse,
  IResponseBase,
  IUserInfoResponse,
  IUserListResponse,
  loginParam,
  loginResonseData,
} from './type'

enum API {
  LOGIN_URL = '/admin/acl/index/login',
  USERINFO_URL = '/admin/acl/index/info',
  USER_LOGOUT = '/admin/acl/index/logout',
}
export const reqLogin = (data: loginParam) =>
  request.post<any, loginResonseData>(API.LOGIN_URL, data)

export const reqUserInfo = () =>
  request.get<any, IUserInfoResponse>(API.USERINFO_URL)

export const reqUserLogOut = (param: any) =>
  request.post<any, any>(API.USER_LOGOUT, param)
export const reqUserList = (page, limit, keyword?) =>
  request.get<any, IUserListResponse>(
    `/admin/acl/user/${page}/${limit}?${keyword ? 'username=' + keyword : ''}`,
  )

export const reqCreateAccount = (param) =>
  request.post<any, any>('/admin/acl/user/save', param)

export const reqRoleToAssign = (adminId: string) =>
  request.get<any, IAssignRoleResponse>(`/admin/acl/user/toAssign/${adminId}`)

export const reqAssignRoleForUser = (param: {
  roleIdList: number[]
  userId: number
}) => request.post<any, IResponseBase>('/admin/acl/user/doAssignRole', param)

export const reqRemoveUsers = (param: any) =>
  request.delete<any, IResponseBase>('/admin/acl/user/batchRemove', {
    data: param,
  })

export const reqRemoveUser = (id: string | number) =>
  request.delete<any, IResponseBase>('/admin/acl/user/remove/' + id)
